﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebManage.Company
{
    public partial class AddCompany : BasePage
    {
        NJL.BLL.NJL_COMPANY bll = new BLL.NJL_COMPANY();
        NJL.Model.NJL_COMPANY model = new Model.NJL_COMPANY();
        NJL.BLL.NJL_CS_AREA bllArea = new BLL.NJL_CS_AREA();
        NJL.BLL.NJL_CUSTOM_AREA bllCustom = new BLL.NJL_CUSTOM_AREA();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (WEBSITE_CODE == "1")
                {
                    DataSet ds = bllArea.GetList("AREA_CODE like '%0000'");
                    ddlProvince.DataSource = ds;
                    ddlProvince.DataTextField = "AREA_NAME";
                    ddlProvince.DataValueField = "AREA_CODE";
                    ddlProvince.DataBind();
                }
                else
                {
                    ddlProvince.Visible = false;
                    string ProvinceId = WEBSITE_CODE.Substring(0, 2);
                    DataSet ds = bllArea.GetList("AREA_CODE like '" + ProvinceId + "%00' and deep=2");
                    ddlCity.DataSource = ds;
                    ddlCity.DataTextField = "AREA_NAME";
                    ddlCity.DataValueField = "AREA_CODE";
                    ddlCity.DataBind();
                }

                litTitle.Text = Request.QueryString["typeName"].ToString();
                ddlCity.Items.Insert(0, new ListItem("------", "000000"));
                ddlArea.Items.Insert(0, new ListItem("------", "000000"));
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

            model.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(100, 999).ToString();
            model.NJL_SYS_BASE_ID = WEBSITE_CODE;
            model.TYPE_CODE = Request.QueryString["typeid"];
            model.NJL_USER_ID = "1";
            model.AREA_CODE = ddlCity.SelectedValue;
            if (FileUpload1.HasFile)
            {
                model.IMAGE_CODE = SaveUploadFile(Request.Files);
            }
            model.COMPANY_NAME = txtName.Text;
            model.COMPANY_NAME_SMS = txtCompanyNameSms.Text.Trim();
            model.ADDRESS = txtAddress.Text;
            model.CONTACT = txtLinkman.Text;
            model.TEL = txtTel.Text;
            model.MOBILE = txtPhone.Text;
            model.QQ = txtQQ.Text;
            model.MSN = txtMsn.Text;
            model.COMPANY_DESCRIPTION = txtServiceProject.Text;
            model.BEST_SIGN = txtTrait.Text;
            model.CREATE_DATE_TIME = DateTime.Now;
            model.UPDATE_DATE_TIME = DateTime.Now;
            model.SEO_TITLE = txtTitle.Text;
            model.SEO_KEYWORDS = txtKeyWords.Text;
            model.SEO_DESCRIPTION = txtDescription.Text;
            model.CREATE_USER_ID = USER_ID;
            model.CREATE_USER_NAME = USER_NAME;
            model.AUDIT_STATE = 0;
            model.SORT = int.Parse(txtSort.Text.Trim());
            model.MAP_ADDRESS = txtMapAddress.Text.Trim();
            model.COMPANY_INTRO = txtCompanyIntro.Text.Trim();
            model.TRAFFIC_GUIDE = txtJTZN.Text.Trim();
            model.IS_SHOW_CONTACT = int.Parse(rblContact.SelectedValue);
            model.IS_OPEN_BOOK = int.Parse(rblyd.SelectedValue);
            model.RECEIVE_SMS_MOBILE = txtSMS.Text.Trim();
            model.AUDIT_INFO_1 = "0";
            model.AUDIT_INFO_2 = "0";
            model.AUDIT_INFO_3 = "0";
            model.AUDIT_INFO_4 = "0";
            model.CLAIM_STATE = 0;
            model.IS_OPEN_BOOK = 0;
            model.IS_SHOW_CONTACT = 0;
            model.VISIT_COUNT = 0;
            model.COMMENT_COUNT = 0;

            model.TICKET_NOTICE = txtTICKET_NOTICE.Text;

            model.POST_CODE = txtPostCode.Text.Trim();
            model.FAX = txtFax.Text.Trim();
            model.CUSTOM_AREA_ID = ddlArea.SelectedValue;
            if (bll.Add(model))
            {
                Royalsoft.Common.MessageBox.ShowAndRedirect(this, "添加成功", "AddCompany.aspx?typeid=" + Request.QueryString["typeid"] + "&typeName=" + Request.QueryString["typeName"]);
            }
        }

        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ProvinceId = ddlProvince.SelectedValue.Substring(0, 2);
            DataSet ds = bllArea.GetList("AREA_CODE like '" + ProvinceId + "%00' and deep=2");
            ddlCity.DataSource = ds;
            ddlCity.DataTextField = "AREA_NAME";
            ddlCity.DataValueField = "AREA_CODE";
            ddlCity.DataBind();
            ListItem list = new ListItem("------", "000000");
            ddlCity.Items.Insert(0, list);
        }

        protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ProvinceId = ddlCity.SelectedValue;
            DataSet ds = bllCustom.GetList("CITY_CODE='" + ProvinceId + "'");
            ddlArea.DataSource = ds;
            ddlArea.DataTextField = "CUSTOM_AREA_NAME";
            ddlArea.DataValueField = "ID";
            ddlArea.DataBind();
            ListItem list = new ListItem("------", "");
            ddlArea.Items.Insert(0, list);
        }
    }
}